package LeetCode;

// 【动态规划】  https://leetcode-cn.com/problems/distinct-subsequences/
public class LC115 {
    public int numDistinct(String s, String t) {
        int slen = s.length();
        int tlen = t.length();
        if(slen==0||tlen==0){
            return 0;
        }
            // 表示以i,j结尾的匹配数量
        int[][] dp = new int[slen + 1][tlen + 1];
        for (int i = 0; i < slen; i++) {
            dp[i][0] = 1;
        }
        for (int i = 1; i <= slen; i++) {
            for (int j = 1; j <= tlen; j++) {
                if (s.charAt(i - 1) == t.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        return dp[slen][tlen];
    }
}
